﻿using PRO.DbProvider;
using PRO.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PRO.ORM;
using System.Data;
using System.Data.Common;
using PRO.Common;

namespace PRO.Data.SqlServer
{
    public partial class DataProvider : IDataProvider
    {
        public int AddProduct(ProductInfo info)
        {
            return info.Insert();
        }
        public DataTable GetProductInfo(int id)
        {
            string sql = "SELECT id,cid,title,des,icon,contents,price,sort,show,edittime from Pro_Product where id=@id";
            DbParameter[] prams = {
									 DbHelper.MakeInParam("@id",(DbType)SqlDbType.Int,4,id)
								   };
            return DbHelper.ExecuteDataset(CommandType.Text, sql, prams).Tables[0];
        }
        public bool EditProduct(ProductInfo info)
        {
            if (info.Icon.IsNullOrWhiteSpace())
                return info.Update("icon");
            else
                return info.Update();
        }
        public DataTable GetCartItems(string ids)
        {
            string sql = "SELECT id,title,price from Pro_Product where (" + ids + ") and show=1";
            return DbHelper.ExecuteDataset(CommandType.Text, sql).Tables[0];
        }
        public bool DelProduct(int id)
        {
            string sql = "delete Pro_Product where id=" + id;
            return Convert.ToBoolean(DbHelper.ExecuteNonQuery(CommandType.Text, sql));
        }
    }
}
